package com.pandacc.controller.fiction;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.support.RequestContextUtils;

import com.pandacc.common.utils.ControllerUtils;
import com.pandacc.pojo.fiction.FictionChaptersDetailsBean;
import com.pandacc.pojo.fiction.FictionDetailsBean;
import com.pandacc.service.fiction.FictionChaptersDetailsService;

/**
 * 处理获取小说章节详情的请求
 * @author duzhiwei
 *
 */
@Controller
@RequestMapping("/b")
public class FictionChaptersDetailsController {
	@Resource(name="chapterService")
	private FictionChaptersDetailsService service;
	
	/**
	 * 取出一本小说的基本信息和所有章节信息
	 * @param factionId
	 * @param req
	 * @param res
	 */
	@RequestMapping(value="/{factionId}", method=RequestMethod.GET)
	@ResponseStatus(HttpStatus.OK)
	public void retrieveAllChapters(@PathVariable("factionId")int factionId
			,HttpServletRequest req, HttpServletResponse res){
		FictionDetailsBean fiction = service.retrieveAllChapters(RequestContextUtils.findWebApplicationContext(req),factionId);
		ControllerUtils.responseWithJson(fiction, res);
	}
	
	/**
	 * 取出一个章节的详细内容
	 * @param factionId
	 * @param chapterId
	 * @param req
	 * @param res
	 */
	@RequestMapping(value="/{factionId}/{chapterId}/c", method=RequestMethod.GET)
	@ResponseStatus(HttpStatus.OK)
	public @ResponseBody FictionChaptersDetailsBean retrieveChapter(@PathVariable("factionId") int factionId,@PathVariable("chapterId") int chapterId
			,HttpServletRequest req, HttpServletResponse res){
		FictionChaptersDetailsBean chapter = service.retrieveChapter(factionId,chapterId);
		return chapter;
	}
	
}
